import { deleteWarningListAPI, fetchWarningListAPI } from '@/api/rod/warnList'

const actions = {
  /* 发送请求获取告警列表的action */
  async fetchWarningList(context, pageParams) {
    const { data } = await fetchWarningListAPI(pageParams)
    context.commit('updateWarningList', data)
  },
  /* 发送请求删除告警的action */
  async deleteWarningList(context, id) {
    const { msg } = await deleteWarningListAPI(id)
    return msg
  }
}
const mutations = {
  /* 更新告警列表的mutation */
  updateWarningList(state, warningListInfo) {
    state.warningListInfo = warningListInfo
  }
}
const state = () => {
  return {
    warningListInfo: {}
  }
}

const getters = {
  warningList(state) {
    return state.warningListInfo.rows
  },
  total(state) {
    return state.warningListInfo.total
  }
}

export default {
  actions,
  mutations,
  state,
  getters,
  namespaced: true
}
